package com.tykboot.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tykboot.core.base.BaseEntity;
import com.tykboot.model.BankTransactionCode;
import com.tykboot.model.CurrencyAmount;
import com.tykboot.model.MerchantDetails;
import com.tykboot.model.ProprietaryBankTransactionCode;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import java.util.Date;
import javax.persistence.*;

/**
 * 
 *
 * @author LiuYu
 */ 
@Entity
@Table(name = "tb_transaction")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class TbTransaction extends BaseEntity {

	/**
	 * 
	 */ 
	@Id
	@GeneratedValue(generator = "jpa-uuid")
	@Column(name = "transactionId")
	private String transactionId;

	/**
	 * 
	 */
	@JsonIgnore
	@Column(name = "financialId")
	private String financialId;

	/**
	 * 
	 */ 
	@Column(name = "accountId")
	private String accountId;

	/**
	 * 
	 */ 
	@Column(name = "transactionReference")
	private String transactionReference;

	/**
	 * 
	 */
    @JsonIgnore
	@Column(name = "amount")
	private String amountDb;

	/**
	 * 
	 */ 
	@Column(name = "creditDebitIndicator")
	private String creditDebitIndicator;

	/**
	 * 
	 */ 
	@Column(name = "status")
	private String status;

	/**
	 * 
	 */ 
	@Column(name = "bookingDateTime")
	private Date bookingDateTime;

	/**
	 * 
	 */ 
	@Column(name = "valueDateTime")
	private Date valueDateTime;

	/**
	 * 
	 */ 
	@Column(name = "transactionInformation")
	private String transactionInformation;

	/**
	 * 
	 */ 
	@Column(name = "addressLine")
	private String addressLine;

	/**
	 * 
	 */
    @JsonIgnore
	@Column(name = "bankTransactionCode")
	private String bankTransactionCodeDb;

	/**
	 * 
	 */
	@JsonIgnore
	@Column(name = "proprietaryBankTransactionCode")
	private String proprietaryBankTransactionCodeDb;

	/**
	 * 
	 */
	@JsonIgnore
	@Column(name = "merchantDetails")
	private String merchantDetailsDb;

	@Transient
    private CurrencyAmount amount;

	@Transient
    private BankTransactionCode bankTransactionCode;

	@Transient
    private ProprietaryBankTransactionCode proprietaryBankTransactionCode;

	@Transient
    private MerchantDetails merchantDetails;

	@Transient
    private TbBalance balance;

    public String getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(String transactionId) {
        this.transactionId = transactionId;
    }

    public String getFinancialId() {
        return financialId;
    }

    public void setFinancialId(String financialId) {
        this.financialId = financialId;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getTransactionReference() {
        return transactionReference;
    }

    public void setTransactionReference(String transactionReference) {
        this.transactionReference = transactionReference;
    }

    public String getAmountDb() {
        return amountDb;
    }

    public void setAmountDb(String amountDb) {
        this.amountDb = amountDb;
    }

    public String getCreditDebitIndicator() {
        return creditDebitIndicator;
    }

    public void setCreditDebitIndicator(String creditDebitIndicator) {
        this.creditDebitIndicator = creditDebitIndicator;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getBookingDateTime() {
        return bookingDateTime;
    }

    public void setBookingDateTime(Date bookingDateTime) {
        this.bookingDateTime = bookingDateTime;
    }

    public Date getValueDateTime() {
        return valueDateTime;
    }

    public void setValueDateTime(Date valueDateTime) {
        this.valueDateTime = valueDateTime;
    }

    public String getTransactionInformation() {
        return transactionInformation;
    }

    public void setTransactionInformation(String transactionInformation) {
        this.transactionInformation = transactionInformation;
    }

    public String getAddressLine() {
        return addressLine;
    }

    public void setAddressLine(String addressLine) {
        this.addressLine = addressLine;
    }

    public String getBankTransactionCodeDb() {
        return bankTransactionCodeDb;
    }

    public void setBankTransactionCodeDb(String bankTransactionCodeDb) {
        this.bankTransactionCodeDb = bankTransactionCodeDb;
    }

    public String getProprietaryBankTransactionCodeDb() {
        return proprietaryBankTransactionCodeDb;
    }

    public void setProprietaryBankTransactionCodeDb(String proprietaryBankTransactionCodeDb) {
        this.proprietaryBankTransactionCodeDb = proprietaryBankTransactionCodeDb;
    }

    public String getMerchantDetailsDb() {
        return merchantDetailsDb;
    }

    public void setMerchantDetailsDb(String merchantDetailsDb) {
        this.merchantDetailsDb = merchantDetailsDb;
    }

    public CurrencyAmount getAmount() {
        if (amount != null) {
            return amount;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getAmountDb())), CurrencyAmount.class);
    }

    public void setAmount(CurrencyAmount amount) {
        this.amount = amount;
    }

    public BankTransactionCode getBankTransactionCode() {
        if (bankTransactionCode != null) {
            return bankTransactionCode;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getBankTransactionCodeDb())), BankTransactionCode.class);
    }

    public void setBankTransactionCode(BankTransactionCode bankTransactionCode) {
        this.bankTransactionCode = bankTransactionCode;
    }

    public ProprietaryBankTransactionCode getProprietaryBankTransactionCode() {
        if (proprietaryBankTransactionCode != null) {
            return proprietaryBankTransactionCode;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getProprietaryBankTransactionCodeDb())), ProprietaryBankTransactionCode.class);
    }

    public void setProprietaryBankTransactionCode(ProprietaryBankTransactionCode proprietaryBankTransactionCode) {
        this.proprietaryBankTransactionCode = proprietaryBankTransactionCode;
    }

    public MerchantDetails getMerchantDetails() {
        if (merchantDetails != null) {
            return merchantDetails;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getMerchantDetailsDb())), MerchantDetails.class);
    }

    public void setMerchantDetails(MerchantDetails merchantDetails) {
        this.merchantDetails = merchantDetails;
    }

    public TbBalance getBalance() {
        return balance;
    }

    public void setBalance(TbBalance balance) {
        this.balance = balance;
    }
}

